package solutions.leetcode.normal

import kotlin.random.Random

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/leetbook/read/top-interview-questions/xmchc3/">384.打乱数组</a>
 */
class Solution384(private val nums: IntArray) {
    var rst = nums.copyOf()
    private val random = Random(9999)

    fun reset(): IntArray {
        return nums
    }

    fun shuffle(): IntArray {
        for (i in 0 until rst.size - 1) {
            val next = random.nextInt(rst.size - i)
            val t = rst[i]
            rst[i] = rst[next]
            rst[next] = t
        }
        return rst
    }
}

fun main() {
    val d = Solution384(arrayOf(1, 2, 3).toIntArray())
    for (i in 0..10) {
        println(d.shuffle().toList())
        println()
    }
}